package com.risk.web.controller.tk;

import com.risk.common.core.controller.BaseController;
import com.risk.common.core.domain.AjaxResult;
import com.risk.common.core.page.TableDataInfo;
import com.risk.common.utils.StringUtils;
import com.risk.kernel.domain.TkCommonDbConfig;
import com.risk.kernel.service.TkCommonDbConfigServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: Liwen
 * @createTime: 2024/12/31
 * @description:
 */
@RestController
@RequestMapping(value = "/tk/db_config/")
public class TkCommonDbConfigController extends BaseController {

    @Autowired
    private TkCommonDbConfigServiceI tkCommonDbConfigService;

    /**
     * 分頁模糊查询列表
     */
    @PreAuthorize("@ss.hasPermi('tk:db_config:list')")
    @GetMapping("/page/list")
    public TableDataInfo list(String keys) {
        startPage();
        List<TkCommonDbConfig> list = tkCommonDbConfigService.selectTkCommonDbConfigList(keys);
        return getDataTable(list);
    }

    /**
     * 新增
     */
    @PreAuthorize("@ss.hasPermi('tk:db_config:add')")
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody TkCommonDbConfig tkCommonDbConfig) {
        String userName = StringUtils.isEmpty(getNickName()) ? getUsername() : getNickName();
        tkCommonDbConfig.setCreateBy(userName);
        return toAjax(tkCommonDbConfigService.insertTkCommonDbConfig(tkCommonDbConfig));
    }


    /**
     * 查詢详细信息
     */
    @PreAuthorize("@ss.hasPermi('tk:db_config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tkCommonDbConfigService.selectTkCommonDbConfigById(id));
    }


    /**
     * 修改
     */
    @PreAuthorize("@ss.hasPermi('tk:db_config:edit')")
    @PutMapping(value = "/edit")
    public AjaxResult edit(@RequestBody TkCommonDbConfig tkCommonDbConfig) {
        return toAjax(tkCommonDbConfigService.updateTkCommonDbConfig(tkCommonDbConfig));
    }

    /**
     * 删除
     */
    @PreAuthorize("@ss.hasPermi('tk:db_config:remove')")
    @DeleteMapping("/bathRemove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tkCommonDbConfigService.deleteTkCommonDbConfigByIds(ids));
    }
}
